/**
 * 动作生成器
 * Created by xingkaihang on 2017/5/24.
 */

import fetch from 'isomorphic-fetch';
import assign from 'object-assign';
import Api from '../constants/api';

export const emptyData = () => {
    return {
        type: 'EMPTYDATA'
    }
}

//获取列表数据
export const fetchPosts = (time) => {
    return dispatch => {
        return fetch(Api.YAHOO + Api.API + time + Api.YAHOO_SUFFIX)
        .then(res => {
            return res.json()
        })
        .then(data => {
            data = data.query.results.json;
            dispatch({
                type: 'GETSUCCESS',
                data: assign({},data)
            })
        })
        .catch(e => {
            console.log(e.message)
        })
    }
}
